<?php
/**
 * ============================================================================
 * 版权所有 2008-2011 多多网络，并保留所有权利。
 * 网站地址: http://soft.duoduo123.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
session_start();
error_reporting(1);
include_once 'comm/config.php';
include_once 'comm/Taoapi.php';
include_once 'comm/page.class.php';
include_once 'comm/func.php';
include("../../public/common.php");
include("../../config/connect.php");
//include_once 'comm/checkpostandget.php';

$page = !($_GET['page'])?'1':intval($_GET['page']);
$pagesize=PAGESIZE;
$itempagesize=PAGESIZE;
$frmnum=($page-1)*$pagesize;
$nick=$_GET['nick'];
$q=$_GET['q'];
if($q=='请输入商品名称...'){$q='';}
$sort=empty($_GET['sort']) ? '' : $_GET['sort']; 
switch ($sort){
	case 'credit_asc':$sort2='seller_credit:asc';break;
	case 'credit_desc':$sort2='seller_credit:desc';break;
	case 'price_asc':$sort2='price:asc';break;
	case 'price_desc':$sort2='price:desc';break;
	case 'commissionNum_asc':$sort2='volume:asc';break;
	case 'commissionNum_desc':$sort2='volume:desc';break;
	default: $sort2='volume:desc';break;
}
$list=$_GET['list'];
if($list!=''){$_SESSION['list']=$list;}
if($list==''){
	$list=$_SESSION['list'];
	if($list==''){$list=LIEBIAO;}
}
$start_price=empty($_GET['start_price'])?'':intval($_GET['start_price']);
$area=$_GET['area'];
$end_price= empty($_GET['end_price'])?'':($_GET['end_price']);
$start_credit=empty($_GET['start_credit'])?'':intval($_GET['start_credit']);
$end_credit=empty($_GET['end_credit'])?'':intval($_GET['end_credit']);

if($nick!="")
{
	/*
	//查找店铺数据库
	$sql="select * from `".$BIAOTOU."shop` where nick='".$nick."'";
	$rs=mysql_query($sql);
	//如果该店铺信息已经存在
	
	if(mysql_num_rows($rs)!=0)
	{
		//如果是简易模式，直接进列表
		if(WEBTYPE=='0')
		{
			echo "<script language=javascript>window.location='shoplist.php?keyword=".urlencode($nick)."';</script>";
			exit;
		}
		while ($row = mysql_fetch_array($rs)) 
		{
			$shoptitle=$row['title'];
			$shopdesc=$row['desc'];
			$shoptype1=$row['type'];
			$item_score=$row['item_score'];
			$service_score=$row['service_score'];
			$delivery_score=$row['delivery_score'];
			$shopcreated=$row['created'];
			$sid=$row['sid'];
			$shoppic=$row['pic_path'];
			$fanxianlv=$row['fanxianlv'];
			if($shoppic=="Array"&&$shoptype1=="B"){$shoppic="/52/d0/T1cWtIXXleXXaCwpjX.png";}
			if($shoppic=="Array"&&$shoptype1=="C"){$shoppic="/99/49/T1fulIXdpaXXartXjX.gif";}
			$shopnick=$row['nick'];
		}		
		$Taoapi_Config = Taoapi_Config::Init();
		$Taoapi_Config->setCharset('UTF-8');
		$Taoapi = new Taoapi;
		$Taoapi->method = 'taobao.users.get';
		$Taoapi->fields = 'nick,consumer_protection,seller_credit,location,type';
		$Taoapi->nicks = $shopnick;
		$TaoapiUsers = $Taoapi->Send('get','xml')->getArrayData();
		$Result_users = $TaoapiUsers["users"]["user"]; 
	
		$shoplevel=$Result_users["seller_credit"]["level"]; 
		$level1=$Result_users["seller_credit"]["level"];
		$shopscore=$Result_users["seller_credit"]["score"];
		$shoptotalnum=$Result_users["seller_credit"]["total_num"];
		$shopgoodnum=$Result_users["seller_credit"]["good_num"];
		$shoptype=$Result_users["type"];
		$shoppro=$Result_users["consumer_protection"];
		$shopcity=$Result_users["location"]["city"];
		$shopstate=$Result_users["location"]["state"];
	
		//更新店铺信息
		$sql2="update `".$BIAOTOU."shop` set level='".$shoplevel."',score='".$shopscore."',total_num='".$shoptotalnum."',good_num='".$shopgoodnum."',type='".$shoptype."',consumer_protection='".$shoppro."' , city='".$shopcity."',state='".$shopstate."',hits=hits+1  where nick='".$shopnick."' limit 1";
		mysql_query($sql2);
		
		//调出商品信息
		$Taoapi->method = 'taobao.items.search';
		$Taoapi->fields = 'iid,num_iid,title,pic_url,price,volume';
		$Taoapi->q = $q;
		$Taoapi->nicks = $shopnick;
		$Taoapi->start_score=$start_credit;
		$Taoapi->end_score=$end_credit;
		$Taoapi->start_price=$start_price;
		$Taoapi->end_price=$end_price;
		$Taoapi->order_by=$sort2;
		$Taoapi->area=$area;
		$Taoapi->page_no=$page;
		$Taoapi->page_size=$pagesize;
		$Taoapi->page_size = $itempagesize;
		$Taoapi->page_no = $page;
		$TaobaokeData_shop = $Taoapi->Send('get','xml')->getArrayData();
		$TaobaokeItem2 = $TaobaokeData_shop['item_search']['items']['item'];
		$total_results = $TaobaokeData_shop['total_results'];
		if($total_results!=1)
			$Itemnum=count($TaobaokeItem2,0);
		else
			$Itemnum=1;
		$TotalResults=$total_results;
		$total=$TotalResults;
		
		$niids="";
		
		if ($total==1){$TaobaokeItem[0]=$TaobaokeItem2;}
		else{$TaobaokeItem=$TaobaokeItem2;}

		//获取iid串
		for($i = 0; $i < $Itemnum; $i++) 
		{
			if($i == 0){
				$niids = $TaobaokeItem[$i]["num_iid"];}
			else{
				$niids = $niids. "," .$TaobaokeItem[$i]["num_iid"];
			}
			$Result_users[$i]=$Result_users;
		}
		//查询单品链接
		$Taoapi->method = 'taobao.taobaoke.items.convert';
		$Taoapi->fields = 'commission,commission_num,num_iid,click_url';
		$Taoapi->nick = MYUSERNICK;
		$Taoapi->num_iids = $niids;
		$comm_TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();
		$comm_TaobaokeItem = $comm_TaobaokeData["taobaoke_items"]["taobaoke_item"];
		
		//组建数组
		for($i = 0; $i < $Itemnum; $i++) 
		{
			for($j=0;$j<$Itemnum;$j++){
				if($TaobaokeItem[$i]["num_iid"]==$comm_TaobaokeItem[$j]["num_iid"]){
					$TaobaokeItem[$i]["click_url"]=$comm_TaobaokeItem[$j]["click_url"];
					$TaobaokeItem[$i]["commission"]=$comm_TaobaokeItem[$j]["commission"];
					$TaobaokeItem[$i]["commission_num"]=$TaobaokeItem[$i]["volume"];
				}
			}
		}	
	}
	else*/
	{
		$Taoapi_Config = Taoapi_Config::Init();
		$Taoapi_Config->setCharset('UTF-8');
		$Taoapi = new Taoapi;
		
		$Taoapi->method = 'taobao.shop.get';
		$Taoapi->fields = 'sid,cid,title,desc,pic_path,created,shop_score';
		$Taoapi->nick = $nick;
		$ShopData = $Taoapi->Send('get','xml')->getArrayData();
		$Result_shop=$ShopData['shop'];
		$shoptitle=$Result_shop['title'];
		$item_score=$Result_shop["shop_score"]["item_score"];
		$service_score=$Result_shop["shop_score"]["service_score"];
		$delivery_score=$Result_shop["shop_score"]["delivery_score"];
		$shopcreated=$Result_shop['created'];
		$sid=$Result_shop['sid'];
		$shoppic=$Result_shop['pic_path'];
		if($shoppic=="Array"&&$shoptype1=="B"){$shoppic="/52/d0/T1cWtIXXleXXaCwpjX.png";}
		if($shoppic=="Array"&&$shoptype1=="C"){$shoppic="/99/49/T1fulIXdpaXXartXjX.gif";}
		$shopnick=$row['nick'];
		
		$Taoapi->method = 'taobao.taobaoke.shops.convert';
		$Taoapi->fields = 'commission_rate';
		$Taoapi->sids = $Result_shop['sid'];
		$Taoapi->nick = $nick;
		$ShopComm = $Taoapi->Send('get','xml')->getArrayData();
		$Result_shopcomm=$ShopComm['taobaoke_shops']['taobaoke_shop']['commission_rate'];
		$fanxianlv=$Result_shopcomm;

		if(count($Result_shop,0)==7)
		{
			$Taoapi->method = 'taobao.user.get';
			$Taoapi->fields = 'user_id,nick,consumer_protection,seller_credit,location,type';
			$Taoapi->nick = $nick;
			$TaoapiUsers = $Taoapi->Send('get','xml')->getArrayData();
			$Result_users = $TaoapiUsers["user"];
			$uid=$Result_users["user_id"];
			$shoptype=$Result_users["type"];
			$shoplevel=$Result_users["seller_credit"]["level"];
			$consumer_protection=$Result_users["consumer_protection"];
			$shopstate=$Result_users["location"]["state"];
			$shopcity=$Result_users["location"]["city"];
			$shopnick=$nick;
			/*if((SHOPCJ=='1')&&(($shoplevel>=SHOPCJS)&&($shoplevel<=SHOPCJE)))
			{
				$good=round($Result_users["seller_credit"]["good_num"]/$Result_users["seller_credit"]["total_num"]*100,2);
				$sql="insert into `".$BIAOTOU."shop` (nick,uid,cid,sid,title,pic_path,created,consumer_protection,level,score,total_num,good_num,city,state,shop_click_url,`type`,`addtime`,item_score,service_score,delivery_score,fanxianlv,good) values ('".$nick."','".$uid."','".$Result_shop['cid']."','".$Result_shop['sid']."','".$Result_shop['title']."','".$Result_shop['pic_path']."','".$Result_shop['created']."','".$Result_users["consumer_protection"]."','".$Result_users["seller_credit"]["level"]."','".$Result_users["seller_credit"]["score"]."','".$Result_users["seller_credit"]["total_num"]."','".$Result_users["seller_credit"]["good_num"]."','".$Result_users["location"]["city"]."','".$Result_users["location"]["state"]."','".$shop_click_url."','".$Result_users["type"]."',".time().",'".$Result_shop["shop_score"]["item_score"]."','".$Result_shop["shop_score"]["service_score"]."','".$Result_shop["shop_score"]["delivery_score"]."','".$Result_shopcomm."','".$good."')";
				mysql_query($sql);
				//如果是简易模式，直接进列表
				if(WEBTYPE=='0'){
					echo "<script language=javascript>window.location='shoplist.php?keyword=".urlencode($shopnick)."';</script>";
					exit;
				}
			}*/
			//调出商品信息
			$Taoapi->method = 'taobao.items.search';
			$Taoapi->fields = 'iid,num_iid,title,pic_url,price,volume';
			$Taoapi->q = $q;
			$Taoapi->nicks = $nick;
			$Taoapi->start_score=$start_credit;
			$Taoapi->end_score=$end_credit;
			$Taoapi->start_price=$start_price;
			$Taoapi->end_price=$end_price;
			$Taoapi->order_by=$sort2;
			$Taoapi->area=$area;
			$Taoapi->page_no=$page;
			$Taoapi->page_size=$pagesize;
			$Taoapi->page_size = $itempagesize;
			$Taoapi->page_no = $page;
			$TaobaokeData_shop = $Taoapi->Send('get','xml')->getArrayData();
			$TaobaokeItem2 = $TaobaokeData_shop['item_search']['items']['item'];
			$total_results = $TaobaokeData_shop['total_results'];
			if($total_results!=1)
				$Itemnum=count($TaobaokeItem2,0);
			else
				$Itemnum=1;
			$TotalResults=$total_results;
			$total=$TotalResults;
		
			$niids="";
			
			if ($total==1){$TaobaokeItem[0]=$TaobaokeItem2;}
			else{$TaobaokeItem=$TaobaokeItem2;}
	
			//获取iid串
			for($i = 0; $i < $Itemnum; $i++) 
			{
				if($i == 0){
					$niids = $TaobaokeItem[$i]["num_iid"];}
				else{
					$niids = $niids. "," .$TaobaokeItem[$i]["num_iid"];
				}
				$Result_users[$i]=$Result_users;
			}
			//查询单品链接
			$Taoapi->method = 'taobao.taobaoke.items.convert';
			$Taoapi->fields = 'commission,commission_rate,commission_num,num_iid,click_url';
			$Taoapi->nick = MYUSERNICK;
			$Taoapi->num_iids = $niids;
			$Taoapi->outer_code = isset($_COOKIE['gwt_userid']) ? $_COOKIE['gwt_userid'] : 0;
			$comm_TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();
			$comm_TaobaokeItem = $comm_TaobaokeData["taobaoke_items"]["taobaoke_item"];
			
			//组建数组
			for($i = 0; $i < $Itemnum; $i++) 
			{
				for($j=0;$j<$Itemnum;$j++){
					if($TaobaokeItem[$i]["num_iid"]==$comm_TaobaokeItem[$j]["num_iid"])
					{
						$TaobaokeItem[$i]["click_url"]=$comm_TaobaokeItem[$j]["click_url"];
						$TaobaokeItem[$i]["commission"]=$comm_TaobaokeItem[$j]["commission"];
						$TaobaokeItem[$i]["commission_rate"]=$comm_TaobaokeItem[$j]["commission_rate"];
						$TaobaokeItem[$i]["commission_num"]=$TaobaokeItem[$i]["volume"];
					}
				}
			}
		}
	}
}

include_once '../s/comm/wjt.php';
$tag="shoplist";
$action_url="shop.php";
//引入模版文件
include 'shop.tpl.php';
//mysql_close($cfg_link);
?>